package com.dospyer.consumer.controller;

import com.dospyer.consumer.service.impl.RestTemplateService;
import com.dospyer.provider.api.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/restTemplate")
public class RestTemplateController {

    @Resource
    private RestTemplateService restTemplateService;

    /**
     * http://localhost:8080/restTemplate/sayHello/123?name=zs&age=18
     */
    @GetMapping(value = "/sayHello/{id}")
    public String greeting(@PathVariable("id") Long id, @RequestParam("name") String name, @RequestParam("age") Integer age) {
        log.info("restTemplate controller sayHello, id={}, name={}, age={}", id, name, age);
        return restTemplateService.sayHello(id, name, age);
    }

    /**
     * http://localhost:8080/restTemplate/?id=123&name=lisi&age=20
     *
     * @param user
     * @return
     */
    @GetMapping(value = "/")
    public String createUser(User user) {
        log.info("restTemplate controller createUser，user={}", user);
        return restTemplateService.createUser(user);
    }
}
